package com.lagou.email.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class EmailController {
    @Autowired
    private JavaMailSender javaMailSender;

    @GetMapping("/email/{email}/{code}")
    public Integer sendEmail(@PathVariable(value = "email") String email, @PathVariable(value = "code") String code) {

        System.out.println("email & code:" + code + email);

        SimpleMailMessage mailMessage = new SimpleMailMessage();
        //发送方
        mailMessage.setFrom("1035459395@qq.com");
        //接收方 youran9908@163.com
        mailMessage.setTo(email);
        //主题
        mailMessage.setSubject("注册验证码");
        //内容
        mailMessage.setText("您的注册验证码: " + code);


        javaMailSender.send(mailMessage);

        return 0;
    }
}
